package com.ftdigital.primemovers_operators.util.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.ftdigital.primemovers_operators.config.GlobalData;

/**
 * Created by Curry on 2016-1-13.
 */
public class ClockDial extends View {
    public ClockDial(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ClockDial(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //绘制外圆
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);//设置为空心
        paint.setAntiAlias(true);
        paint.setStrokeWidth(5);
        canvas.drawCircle(GlobalData.screenWidth / 2, GlobalData.screenHeight / 2, GlobalData.screenWidth / 2, paint);
       //绘制商标
        Paint textPaint = new Paint();
        textPaint.setTextSize(60);
        canvas.drawText("OMEGA", GlobalData.screenWidth / 2 - textPaint.measureText("OMEGA")/2, GlobalData.screenHeight / 2 - GlobalData.screenWidth/4, textPaint);

        //绘制刻度
        Paint paintDegerr = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(3);
        for (int i = 0; i < 12; i++) {
            if (i == 0 || i == 3 || i == 6 || i == 9) {
                paintDegerr.setStrokeWidth(10);
                paintDegerr.setTextSize(45);
                canvas.drawLine(GlobalData.screenWidth / 2, GlobalData.screenHeight / 2 - GlobalData.screenWidth / 2,
                        GlobalData.screenWidth / 2, GlobalData.screenHeight / 2 - GlobalData.screenWidth / 2 + 100, paintDegerr);
                canvas.drawText(String.valueOf(i), GlobalData.screenWidth / 2 - paintDegerr.measureText(String.valueOf(i)) / 2, GlobalData.screenHeight / 2 - GlobalData.screenWidth / 2 + 145, paintDegerr);
            } else {
                paintDegerr.setStrokeWidth(5);
                paintDegerr.setTextSize(30);
                canvas.drawLine(GlobalData.screenWidth / 2, GlobalData.screenHeight / 2 - GlobalData.screenWidth / 2,
                        GlobalData.screenWidth / 2, GlobalData.screenHeight / 2 - GlobalData.screenWidth / 2 + 70, paintDegerr);
                canvas.drawText(String.valueOf(i), GlobalData.screenWidth / 2 - paintDegerr.measureText(String.valueOf(i)) / 2, GlobalData.screenHeight / 2 - GlobalData.screenWidth / 2 + 130, paintDegerr);
            }
            canvas.rotate(30, GlobalData.screenWidth / 2, GlobalData.screenHeight / 2);//旋转角度
        }
        canvas.save();//保存滑板

        //绘制指针
        canvas.translate(GlobalData.screenWidth / 2, GlobalData.screenHeight / 2);//移动坐标点到置顶位置

        Paint HourPaint = new Paint();
        HourPaint.setStrokeWidth(20);
        Paint MinPaint = new Paint();
        MinPaint.setStrokeWidth(10);

        canvas.drawLine(0, 0, 100, 200, HourPaint);
        canvas.drawLine(0, 0, 100, 100, MinPaint);
        canvas.restore();//合并层

    }
}
